import 'dart:async';

import 'package:hongsheng/api/SPClassApiManager.dart';
import 'package:hongsheng/api/SPClassHttpCallBack.dart';
import 'package:hongsheng/app/SPClassApplicaion.dart';
import 'package:hongsheng/model/SPClassBaseModelEntity.dart';
import 'package:hongsheng/model/MatchAiListBuyListEntity.dart';
import 'package:hongsheng/model/MatchAiListEntity.dart';
import 'package:hongsheng/pages/common/SPClassDialogUtils.dart';
import 'package:hongsheng/pages/user/SPClassRechargeDiamondPage.dart';
import 'package:hongsheng/utils/SPClassCommonMethods.dart';
import 'package:hongsheng/utils/SPClassDateUtils.dart';
import 'package:hongsheng/utils/SPClassImageUtil.dart';
import 'package:hongsheng/utils/SPClassNavigatorUtils.dart';
import 'package:hongsheng/utils/SPClassToastUtils.dart';
import 'package:hongsheng/utils/colors.dart';
import 'package:hongsheng/widgets/nested_scroll_view_inner_scroll_position_key_widget.dart';
import 'package:flutter/material.dart' ;
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'SPClassCalculatePage.dart';
import 'SPClassPanDian.dart';

///ai预测
class SPClassAIPage extends StatefulWidget {
  const SPClassAIPage({Key ?key}) : super(key: key);

  @override
  SPClassAIPageState createState() => SPClassAIPageState();
}

class SPClassAIPageState extends State<SPClassAIPage>
    with TickerProviderStateMixin {
  ScrollController _scrollController = new ScrollController();
  bool spProShowMsg = false;
  ScrollController spProMsgScrollController = new ScrollController();
  TabController ?spProTabController;
  List spProTabTitles = ['30天战绩', '今日推荐', '战绩盘点'];
  List<MatchAiListBuyDataEntity> buyList = [];
  Timer ?_timer;
  static String matchType = '足球';

  MatchAiListAiVipEntity ?data;
  Animation<double> ?animation;
  AnimationController ?controller;
  double xValue = -150;
  bool isShowTypeSelect = false;

  String maxSum = '0';
  String weekSum = '0';
  String yesterdayRedNum = '0';
  String recentRedNum = '0';
  List<Widget> views = [];
  var myEventBus;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    views.add(SPClassCalculatePage(
      type: 0,
    ));
    views.add(SPClassCalculatePage(
      type: 1,
    ));
    views.add(SPClassPanDian());
    getAiVip();

    spProTabController = new TabController(
        length: spProTabTitles.length, vsync: this, initialIndex: 1);
    // _timer= Timer.periodic(Duration(seconds: 2), (timer){
    //   if(spProMsgScrollController.positions.isNotEmpty){
    //     spProMsgScrollController.animateTo(spProMsgScrollController.offset+width(31), duration: Duration(seconds:2), curve: Curves.linear);
    //   }
    // });
    // getBuyList();

    controller = new AnimationController(
        duration: const Duration(milliseconds: 300), vsync: this);
    animation = new Tween(begin: 0.0, end: 150.0).animate(controller!)
      ..addListener(() {
        if (isShowTypeSelect) {
          xValue = -150 + animation!.value;
        } else {
          xValue = 0 - animation!.value;
        }
        setState(() {});
      });

    myEventBus = SPClassApplicaion.spProEventBus.on<String>().listen((event) {
      if (event.startsWith("updateNum:")) {
        maxSum = event.substring(10).split(';')[0];
        weekSum = event.substring(10).split(';')[1];
        yesterdayRedNum = event.substring(10).split(';')[2];
        recentRedNum = event.substring(10).split(';')[3];
        setState(() {});
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      bottomNavigationBar: SafeArea(
        bottom: true,
        child: data == null || data!.spProIsAiVip == '1'
            ? Container(
                height: 0,
              )
            : Container(
                height: width(60),
                padding: EdgeInsets.symmetric(horizontal: width(12)),
                decoration: BoxDecoration(
                  // borderRadius: BorderRadius.circular(4),
                  gradient: LinearGradient(
                    colors: [
                      Color(0xFFEC7E3A),
                      Color(0xFFE33A30),
                    ],
                  ),
                ),
                child: Row(
                  children: <Widget>[
                    Text(
                      '$matchType周套餐:',
                      style: TextStyle(color: Colors.white, fontSize: sp(14)),
                    ),
                    Text(
                      '${data!.spProAiWeekPrice}',
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: sp(17),
                          fontWeight: FontWeight.bold,
                          height: 1.1),
                    ),
                    Text(
                      '元',
                      style: TextStyle(color: Colors.white, fontSize: sp(14)),
                    ),
                    Expanded(
                      child: SizedBox(),
                    ),
                    Text(
                      '(${SPClassDateUtils.spFunDateFormatByString(DateTime.now().toString(), "MM.dd")}-${SPClassDateUtils.spFunDateFormatByString(DateTime.now().add(Duration(days: 7)).toString(), "MM.dd")})',
                      style: TextStyle(color: Colors.white, fontSize: sp(12)),
                    ),
                    SizedBox(
                      width: width(4),
                    ),
                    GestureDetector(
                      onTap: () {
                        if (spFunIsLogin(context: context)) {
                          spFunShowConfirmDialog();
                        }
                      },
                      child: Container(
                        width: width(60),
                        height: width(30),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: Color(0xFFFDAD4C),
                            borderRadius: BorderRadius.circular(2)),
                        child: Text(
                          '订阅',
                          style:
                              TextStyle(color: Colors.white, fontSize: sp(14)),
                        ),
                      ),
                    )
                  ],
                ),
              ),
      ),
      body: Stack(
        children: <Widget>[
          NestedScrollView(
            controller: _scrollController,
            headerSliverBuilder:
                (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                SliverAppBar(
                  elevation: 0,
                  centerTitle: true,
                  pinned: true,
                  leading: FlatButton(
                    child: Icon(
                      Icons.arrow_back_ios,
                      size: width(20),
                      color: Colors.white,
                    ),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  ),
                  backgroundColor:Colors.red ,
                  expandedHeight:
                      width(247) - MediaQuery.of(context).padding.top,
                  flexibleSpace: FlexibleSpaceBar(
                    collapseMode: CollapseMode.pin,
                    background: Stack(
                      children: <Widget>[
                        Image.asset(
                          SPClassImageUtil.spFunGetImagePath("ic_ai"),
                          fit: BoxFit.fill,
                          width: MediaQuery.of(context).size.width,
                        ),
                        Positioned(
                          bottom: 0,
                          left: 0,
                          right: 0,
                          child: Column(
                            children: [
                              Container(
                                padding: EdgeInsets.symmetric(
                                    horizontal: width(15), vertical: width(4)),
                                margin: EdgeInsets.symmetric(
                                  horizontal: width(20),
                                ),
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.vertical(top: Radius.circular(4)),
                                  color: Colors.white.withOpacity(0.2),
                                ),
                                child: Text(
                                  '红胜AI预测，是基于万场比赛的盘口和热度信息得出的人工智能预测模型，经专家全力研究得出，推荐结果科学稳定。',
                                  style: TextStyle(
                                      fontSize: sp(11), color: Colors.white),
                                ),
                              ),
                              Container(
                                decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(4),
                                    gradient: LinearGradient(
                                      begin: Alignment.topCenter,
                                      end: Alignment.bottomCenter,
                                      colors: [
                                        Color(0xFF1F4399),
                                        Color(0xFF1B3266),
                                        Color(0xFF213666),
                                      ],
                                    )),
                                child: Row(
                                  children: <Widget>[
                                    Expanded(
                                      child: Container(
                                        height: width(45),
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: <Widget>[
                                            RichText(
                                              text: TextSpan(
                                                  style: TextStyle(
                                                      fontSize: sp(15),
                                                      color: Color(0xFF05F6CB)),
                                                  text: '$maxSum',
                                                  children: [
                                                    TextSpan(
                                                      style: TextStyle(
                                                          fontSize: sp(10),
                                                          color: Color(
                                                              0xFF05F6CB)),
                                                      text: '场',
                                                    ),
                                                  ]),
                                            ),
                                            Text(
                                              '累计命中场数',
                                              style: TextStyle(
                                                  fontSize: sp(11),
                                                  color: Colors.white),
                                            ),
                                          ],
                                        ),
                                        decoration: BoxDecoration(
                                          color: Color(0xFF5D8AF7)
                                              .withOpacity(0.2),
                                          borderRadius:
                                              BorderRadius.circular(2),
                                        ),
                                      ),
                                    ),
                                    SizedBox(
                                      width: width(4),
                                    ),
                                    Expanded(
                                      child: Container(
                                        height: width(45),
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: <Widget>[
                                            RichText(
                                              text: TextSpan(
                                                  style: TextStyle(
                                                      fontSize: sp(15),
                                                      color: Color(0xFF05F6CB)),
                                                  text: '$weekSum',
                                                  children: [
                                                    TextSpan(
                                                      style: TextStyle(
                                                          fontSize: sp(10),
                                                          color: Color(
                                                              0xFF05F6CB)),
                                                      text: '场',
                                                    ),
                                                  ]),
                                            ),
                                            Text(
                                              '近7天命中',
                                              style: TextStyle(
                                                  fontSize: sp(11),
                                                  color: Colors.white),
                                            ),
                                          ],
                                        ),
                                        decoration: BoxDecoration(
                                          color: Color(0xFF5D8AF7)
                                              .withOpacity(0.2),
                                          borderRadius:
                                              BorderRadius.circular(2),
                                        ),
                                      ),
                                    ),
                                    SizedBox(
                                      width: width(4),
                                    ),
                                    Expanded(
                                      child: Container(
                                        height: width(45),
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: <Widget>[
                                            RichText(
                                              text: TextSpan(
                                                  style: TextStyle(
                                                      fontSize: sp(15),
                                                      color: Color(0xFF05F6CB)),
                                                  text: '$yesterdayRedNum',
                                                  children: [
                                                    TextSpan(
                                                      style: TextStyle(
                                                          fontSize: sp(10),
                                                          color: Color(
                                                              0xFF05F6CB)),
                                                      text: '场',
                                                    ),
                                                  ]),
                                            ),
                                            Text(
                                              '昨日命中',
                                              style: TextStyle(
                                                  fontSize: sp(11),
                                                  color: Colors.white),
                                            ),
                                          ],
                                        ),
                                        decoration: BoxDecoration(
                                          color: Color(0xFF5D8AF7)
                                              .withOpacity(0.2),
                                          borderRadius:
                                              BorderRadius.circular(2),
                                        ),
                                      ),
                                    ),
                                    SizedBox(
                                      width: width(4),
                                    ),
                                    Expanded(
                                      child: Container(
                                        height: width(45),
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.center,
                                          children: <Widget>[
                                            RichText(
                                              text: TextSpan(
                                                  style: TextStyle(
                                                      fontSize: sp(15),
                                                      color: Color(0xFF05F6CB)),
                                                  text: '$recentRedNum',
                                                  children: [
                                                    TextSpan(
                                                      style: TextStyle(
                                                          fontSize: sp(10),
                                                          color: Color(
                                                              0xFF05F6CB)),
                                                      text: '场',
                                                    ),
                                                  ]),
                                            ),
                                            Text(
                                              '最近连红',
                                              style: TextStyle(
                                                  fontSize: sp(11),
                                                  color: Colors.white),
                                            ),
                                          ],
                                        ),
                                        decoration: BoxDecoration(
                                          color: Color(0xFF5D8AF7)
                                              .withOpacity(0.2),
                                          borderRadius:
                                              BorderRadius.circular(2),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                                padding: EdgeInsets.symmetric(
                                    horizontal: width(6), vertical: width(8)),
                                margin: EdgeInsets.symmetric(
                                  horizontal: width(10),
                                ),
                              )
                            ],
                          ),
                        ),
                        Positioned(
                          bottom: width(60),
                          right: width(10),
                          child: Image.asset(
                            SPClassImageUtil.spFunGetImagePath('ic_ai_logo',),
                            width: width(35),
                          ),
                        )
                        // Positioned(
                        //   bottom:0,
                        //   left:0,
                        //   right:0,
                        //   child: Container(
                        //     margin: EdgeInsets.symmetric(horizontal: width(10)),
                        //     padding: EdgeInsets.all(width(8)),
                        //     height: width(122),
                        //     decoration: BoxDecoration(
                        //       borderRadius: BorderRadius.circular(4),
                        //       gradient:LinearGradient(
                        //         begin: Alignment.topCenter,
                        //         end: Alignment.bottomCenter,
                        //         colors: [
                        //           Color(0xFF1F4399),
                        //           Color(0xFF1B3266),
                        //           Color(0xFF213666),
                        //         ],
                        //       )
                        //     ),
                        //     child: Column(
                        //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        //       children: <Widget>[
                        //         Row(
                        //           children: <Widget>[
                        //             Image.asset(
                        //               SPClassImageUtil.spFunGetImagePath('ic_ai_logo',),
                        //               width: width(35),
                        //             ),
                        //             Expanded(
                        //               child: Text('红胜AI预测，是基于万场比赛的盘口和热度信息得出的人工智能预测模型，经专家全力研究得出，推荐结果科学稳定。',
                        //                 style: TextStyle(fontSize: sp(11),color: Colors.white),),
                        //             )
                        //           ],
                        //         ),
                        //         Row(
                        //           children: <Widget>[
                        //             Expanded(
                        //               child: Container(
                        //                 height:width(45),
                        //                 child:Column(
                        //                   mainAxisAlignment: MainAxisAlignment.center,
                        //                   children: <Widget>[
                        //                     RichText(
                        //                       text: TextSpan(
                        //                           style: TextStyle(fontSize: sp(15),color: Color(0xFF05F6CB)),
                        //                           text: '$maxSum',
                        //                           children: [
                        //                             TextSpan(
                        //                               style: TextStyle(fontSize: sp(10),color: Color(0xFF05F6CB)),
                        //                               text: '场',
                        //                             ),
                        //                           ]
                        //                       ),
                        //                     ),
                        //                     Text('累计命中场数',style: TextStyle(fontSize: sp(11),color: Colors.white),),
                        //                   ],
                        //                 ),
                        //                 decoration: BoxDecoration(
                        //                   color: Color(0xFF5D8AF7).withOpacity(0.2),
                        //                   borderRadius: BorderRadius.circular(2),
                        //                 ),
                        //               ),
                        //             ),
                        //             SizedBox(width: width(4),),
                        //             Expanded(
                        //               child: Container(
                        //                 height:width(45),
                        //                 child:Column(
                        //                   mainAxisAlignment: MainAxisAlignment.center,
                        //                   children: <Widget>[
                        //                     RichText(
                        //                       text: TextSpan(
                        //                           style: TextStyle(fontSize: sp(15),color: Color(0xFF05F6CB)),
                        //                           text: '$weekSum',
                        //                           children: [
                        //                             TextSpan(
                        //                               style: TextStyle(fontSize: sp(10),color: Color(0xFF05F6CB)),
                        //                               text: '场',
                        //                             ),
                        //                           ]
                        //                       ),
                        //                     ),
                        //                     Text('近7天命中',style: TextStyle(fontSize: sp(11),color: Colors.white),),
                        //                   ],
                        //                 ),
                        //                 decoration: BoxDecoration(
                        //                   color: Color(0xFF5D8AF7).withOpacity(0.2),
                        //                   borderRadius: BorderRadius.circular(2),
                        //                 ),
                        //               ),
                        //             ),
                        //             SizedBox(width: width(4),),
                        //             Expanded(
                        //               child: Container(
                        //                 height:width(45),
                        //                 child:Column(
                        //                   mainAxisAlignment: MainAxisAlignment.center,
                        //                   children: <Widget>[
                        //                     RichText(
                        //                       text: TextSpan(
                        //                           style: TextStyle(fontSize: sp(15),color: Color(0xFF05F6CB)),
                        //                           text: '$maxRedNum',
                        //                           children: [
                        //                             TextSpan(
                        //                               style: TextStyle(fontSize: sp(10),color: Color(0xFF05F6CB)),
                        //                               text: '场',
                        //                             ),
                        //                           ]
                        //                       ),
                        //                     ),
                        //                     Text('昨日命中',style: TextStyle(fontSize: sp(11),color: Colors.white),),
                        //                   ],
                        //                 ),
                        //                 decoration: BoxDecoration(
                        //                   color: Color(0xFF5D8AF7).withOpacity(0.2),
                        //                   borderRadius: BorderRadius.circular(2),
                        //                 ),
                        //               ),
                        //             ),
                        //             SizedBox(width: width(4),),
                        //             Expanded(
                        //               child: Container(
                        //                 height:width(45),
                        //                 child:Column(
                        //                    mainAxisAlignment: MainAxisAlignment.center,
                        //                   children: <Widget>[
                        //                     RichText(
                        //                       text: TextSpan(
                        //                           style: TextStyle(fontSize: sp(15),color: Color(0xFF05F6CB)),
                        //                           text: '$maxRedNum',
                        //                           children: [
                        //                             TextSpan(
                        //                                 style: TextStyle(fontSize: sp(10),color: Color(0xFF05F6CB)),
                        //                                 text: '场',
                        //                             ),
                        //                           ]
                        //                       ),
                        //                     ),
                        //                     Text('最近连红',style: TextStyle(fontSize: sp(11),color: Colors.white),),
                        //                   ],
                        //                 ),
                        //                 decoration: BoxDecoration(
                        //                   color: Color(0xFF5D8AF7).withOpacity(0.2),
                        //                   borderRadius: BorderRadius.circular(2),
                        //                 ),
                        //               ),
                        //             ),
                        //           ],
                        //         )
                        //       ],
                        //     ),
                        //   ),
                        // )
                      ],
                      overflow: Overflow.visible,
                    ),
                  ),
                  title: Text('AI预测'),
                ),
              ];
            },
            // pinnedHeaderSliverHeightBuilder: () {
            //   return kToolbarHeight + MediaQuery.of(context).padding.top;
            // },
            // innerScrollPositionKeyBuilder: () {
            //   var index = "Tab";
            //   index += spProTabController.index.toString();
            //   return Key(index);
            // },
            body: Column(
              children: <Widget>[
                Container(
                  height: width(40),
                  margin: EdgeInsets.only(
                      left: width(12), right: width(12), top: width(8)),
                  decoration: BoxDecoration(color: Colors.white, boxShadow: [
                    BoxShadow(
                      offset: const Offset(0, 0),
                      color: const Color(0xFF000000).withOpacity(0.1),
                      blurRadius: width(6),
                    ),
                  ]),
                  child:
                  TabBar(
                    labelColor: const Color(0xFFE3494B),
                    labelPadding: EdgeInsets.zero,
                    unselectedLabelColor: MyColors.grey_99,
                    indicatorColor: Colors.red[500],
                    isScrollable: false,
                    indicatorSize: TabBarIndicatorSize.label,
                    labelStyle: TextStyle(
                        fontSize: sp(17), fontWeight: FontWeight.bold),
                    unselectedLabelStyle: TextStyle(
                      fontSize: sp(17),
                    ),
                    controller: spProTabController,
                    tabs: spProTabTitles.map((key) {
                      return Tab(
                        text: key,
                      );
                    }).toList(),
                  ),
                ),
                SizedBox(
                  height: width(4),
                ),
                Expanded(
                  child: TabBarView(
                    controller: spProTabController,
                    children: views.map((e) {
                      return NestedScrollViewInnerScrollPositionKeyWidget(
                          Key('Tab' + views.indexOf(e).toString()), e);
                    }).toList(),
                  ),
                )
              ],
            ),
          ),
          isShowTypeSelect
              ? GestureDetector(
                  onTap: () {
                    isShowTypeSelect = false;
                    controller?.reset();
                    controller?.forward();
                  },
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    height: MediaQuery.of(context).size.height,
                    color: Colors.black.withOpacity(0.4),
                  ),
                )
              : Container(
                  width: MediaQuery.of(context).size.width,
                  height: MediaQuery.of(context).size.height,
                ),
          Positioned(
            right: xValue,
            bottom: width(100),
            child: GestureDetector(
              behavior: HitTestBehavior.translucent,
              onTap: () {
                isShowTypeSelect = !isShowTypeSelect;
                controller?.reset();
                controller?.forward();
              },
              child: Container(
                height: width(60),
                width: 200,
                decoration: BoxDecoration(
                    color: isShowTypeSelect ? Colors.white : Colors.transparent,
                    borderRadius:
                        BorderRadius.horizontal(left: Radius.circular(150))),
                child: isShowTypeSelect
                    ? Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text(
                            '赛事选择：',
                            style: TextStyle(fontSize: sp(11)),
                          ),
                          GestureDetector(
                            behavior: HitTestBehavior.translucent,
                            onTap: () {
                              SPClassAIPageState.matchType = '足球';
                              isShowTypeSelect = false;
                              getAiVip();
                              controller?.reset();
                              controller?.forward();
                              SPClassApplicaion.spProEventBus
                                  .fire("aiRefresh:$matchType");
                              setState(() {});
                            },
                            child: Image.asset(
                                SPClassImageUtil.spFunGetImagePath(
                                    "ic_football"),
                                fit: BoxFit.fill,
                                width: width(40)),
                          ),
                          SizedBox(
                            width: width(11),
                          ),
                          GestureDetector(
                            behavior: HitTestBehavior.translucent,
                            onTap: () {
                              SPClassAIPageState.matchType = '篮球';
                              isShowTypeSelect = false;
                              getAiVip();
                              controller?.reset();
                              controller?.forward();
                              SPClassApplicaion.spProEventBus
                                  .fire("aiRefresh:$matchType");
                              setState(() {});
                            },
                            child: Image.asset(
                                SPClassImageUtil.spFunGetImagePath(
                                    'ic_basketball'),
                                fit: BoxFit.fill,
                                width: width(40)),
                          ),
                        ],
                      )
                    : Row(
                        children: <Widget>[
                          SizedBox(
                            width: width(25),
                          ),
                          Image.asset(
                              SPClassImageUtil.spFunGetImagePath(
                                  matchType == '足球'
                                      ? "ic_football"
                                      : "ic_basketball"),
                              fit: BoxFit.fill,
                              width: width(40)),
                        ],
                      ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  getAiVip() {
    data = null;
    setState(() {});
    SPClassApiManager.spFunGetInstance()
        .spFunMatchAiVip<MatchAiListAiVipEntity>(
            params: {'match_type': matchType},
            spProCallBack: SPClassHttpCallBack(spProOnSuccess: (result) {
              data = result;
              setState(() {});
            }));
  }

  getBuyList() {
    SPClassApiManager.spFunGetInstance()
        .spFunMatchBuyList<MatchAiListBuyListEntity>(
            params: {},
            spProCallBack: SPClassHttpCallBack(spProOnSuccess: (result) {
              buyList = result.spProBuyList;
              if (buyList.isNotEmpty) {
                spProShowMsg = true;
              }
              setState(() {});
            }));
  }

  void spFunShowConfirmDialog() {
    SPClassDialogUtils.spFunShowConfirmDialog(
        context,
        RichText(
          text: TextSpan(
            text: "支付",
            style: TextStyle(fontSize: 16, color: Color(0xFF333333)),
            children: <TextSpan>[
              TextSpan(
                  text: data?.spProAiWeekPrice??'0',
                  style: TextStyle(fontSize: 16, color: Color(0xFFE3494B))),
              TextSpan(text: "钻石"),
              TextSpan(text: "订阅${matchType}AI赛事预测"),
            ],
          ),
        ), () {
      SPClassApiManager.spFunGetInstance()
          .spFunMatchBuyAi<SPClassBaseModelEntity>(
              params: {'match_type': matchType,'buy_type':'week'},
              context: context,
              spProCallBack: SPClassHttpCallBack(spProOnSuccess: (value) {
                SPClassToastUtils.spFunShowToast(msg: '订阅成功');
                getAiVip();
              }, onError: (value) {
                if (value.code == "200") {
                  SPClassNavigatorUtils.spFunPushRoute(
                      context, SPClassRechargeDiamondPage());
                }
              }));
    });
  }

  @override
  void dispose() {
    myEventBus.cancel();
    controller?.dispose();
    // TODO: implement dispose
    super.dispose();
  }
}
